/**
	*****************************************
	* @file call_back.c
	* @author Chensy
	* @brief 回调函数处理
	* @version 1.0
	* @date 2025-03-02
	* 
	* @copyright Copyright (c) 2025
	*
	******************************************
 **/	
#include "call_back.h"

/**
  * @brief 应急情况处理，遥控器四个拨杆都打到最底下触发，切断电源
  * @retval 无
  */
int8_t EMG =0; //紧急情况标识符
void Emergency_handling(void)
{
    const remoter_t *rc = get_remote_control_point();
    if(rc->joy.SWA == 1807&&rc->joy.SWA == 1807
        &&rc->joy.SWA == 1807&&rc->joy.SWA == 1807)
    {
				EMG = 1;
				HAL_GPIO_WritePin(IN2_GPIO_Port,IN2_Pin,GPIO_PIN_SET);
    }
		else EMG = 0;

}


/**
  * @brief 串口回调函数
  * @retval 无
  */
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
	//处理上位机数据
	if (huart == &huart1 )
	{
		
	}
	
	//接收遥控器
	/*
	if(huart == &huart3)
	{
		
	
	}
	*/
	
		if (huart == &huart6 )
		{
			if(jetson_rx_buffer[0] == PACKET_HEADER && jetson_rx_buffer[PACKET_SIZE - 1] == PACKET_FOOTER )
			{
				memcpy(Jetson_r.buffer,jetson_rx_buffer,PACKET_SIZE);
				Jetson_Parse(&Jetson_r);
			}
			
			HAL_UARTEx_ReceiveToIdle_IT(&huart6, jetson_rx_buffer, PACKET_SIZE);
	 }

}
 

/**
  * @brief CAN中断回调函数
  * @retval 无
  */
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan) {
    if (hcan == kMotorCan1) {
        ProcessCANMessage(kMotorCan1, dji_can1_motor_list);
    }
		
		if (hcan == kMotorCan2) {
        ProcessCANMessage(kMotorCan2, dji_can2_motor_list);
    }
}



/**
  * @brief 主回调函数（定时器7中断处理）
  * @retval 无
  */
void MainCallBack(void)
{
		
		DjiMotorSend();//发送大疆电机数据
		state_machine_update();//更新状态机
		Emergency_handling();
    
		//Send_vofa();//调试
}


